import cv2
import numpy as np
import pylab
import matplotlib.pyplot as plt

lena = cv2.imread('train_image/dollor.png')

# 1.按照索引拆分
# b = lena[:, :, 0]
# g = lena[:, :, 1]
# r = lena[:, :, 2]
b, g, r = cv2.split(lena)

# pylab.subplot(1, 3, 1)
pylab.imshow(b, cmap=plt.cm.gray)
pylab.show()

# lena[:, :, 1] = 0
# lena[:, :, 2] = 0
# cv2.imwrite("train_image/dollor_b.png", lena)


# pylab.subplot(1, 3, 2)
# pylab.imshow(g)
# pylab.show()
#
#
# pylab.subplot(1, 3, 3)
# pylab.imshow(r)
# pylab.show()

#
# cv2.imshow("merge", cv2.merge((b, g, r)))
# cv2.waitKey(0)

# 通道的合并
pylab.imshow(cv2.cvtColor(cv2.merge((b, g, r)), cv2.COLOR_BGR2RGB))
pylab.show()


newImage = np.zeros((3,3,3), dtype=np.uint8)
newImage[:,:,:] = 0
print("彩色图像lena属性:")
print("color_lena.shape={}".format(newImage.shape))
print("color_lena.size={}".format(newImage.size))
print("color_lena.dtype={}".format(newImage.dtype))
